package com.io.files;

import java.io.File;
import java.io.IOException;

public class Example03 {
    public static void main(String[] args) throws IOException {
        System.out.println("相对路径和绝对路径测试");
        //File file = new File("E:\\JavaProject\\java-learning-directory\\CommonClass\\src\\com\\io\\files\\test.txt");
        File file = new File("E:\\JavaProject\\java-learning-directory\\CommonClass\\src\\com\\io\\files\\","test.txt");
        System.out.println(file);
        // 获取路径的三种方式
        // 1.获取传入时的路径
        String path = file.getPath();
        System.out.println(path);
        // 2.获取绝对路径 getAbsolutePath()
        String absolutePath = file.getAbsolutePath();
        System.out.println(absolutePath); // E:\JavaProject\java-learning-directory\.\test.txt
        // 3.获取规范化路径
        String canonicalPath = file.getCanonicalPath();
        System.out.println(canonicalPath); // E:\JavaProject\java-learning-directory\test.txt
        System.out.println(file.length());
        System.out.println("-----");
        // 是否为目录？
        boolean directory = file.isDirectory();
        System.out.println(directory);
        // 是否为文件？
        boolean file1 = file.isFile();
        System.out.println(file1);
        // 文件或者目录是否存在？
        File fileExists = new File("E:\\JavaProject\\java-learning-directory\\CommonClass\\src\\com\\io\\files\\","test01.txt");
        boolean exists = fileExists.exists();
        System.out.println(exists);
    }
}
